import { ClassService } from '@/services/class';
import { ClrService } from '@/services/classroom';
import { PageContainer } from '@ant-design/pro-components';
import { useEffect, useMemo, useState } from 'react';
import BeginForm from './components/BeginForm';
import ClassList from './components/ClassList';
import CreateForm from './components/CreatForm';
import UpdateForm from './components/UpdateForm';

const ClassPage: React.FC = () => {
  const [teacher, setTeacher] = useState<any>([]);
  useEffect(() => {
    (async () => {
      const teacher = await ClassService.categoryStaffList(4);
      setTeacher(teacher);
    })();
  }, []);
  const [admin, setAdmin] = useState<any>([]);
  useEffect(() => {
    (async () => {
      const admin = await ClassService.categoryStaffList(5);
      setAdmin(admin);
    })();
  }, []);
  const [job, setJob] = useState<any>([]);
  useEffect(() => {
    (async () => {
      const job = await ClassService.categoryStaffList(6);
      setJob(job);
    })();
  }, []);
  const teacherEnum = useMemo(() => {
    const result = new Map();
    result.set(0, { text: '--请选择--' });
    teacher.forEach((item) => result.set(item.stf_id, { text: item.stf_name }));
    return result;
  });
  const adminEnum = useMemo(() => {
    const result = new Map();
    result.set(0, { text: '--请选择--' });
    admin.forEach((item) => result.set(item.stf_id, { text: item.stf_name }));
    return result;
  });
  const jobEnum = useMemo(() => {
    const result = new Map();
    result.set(0, { text: '--请选择--' });
    job.forEach((item) => result.set(item.stf_id, { text: item.stf_name }));
    return result;
  });

  const [echoModel, setEchoModel] = useState<any>([]);
  useEffect(() => {
    (async () => {
      const data = await ClrService.getClrList();
      setEchoModel(data);
    })();
  }, []);
  const ClrId = echoModel.map((item) => item.clsr_id);
  const clrCategoryEnum = useMemo(() => {
    const result = new Map();
    result.set(0, { text: '- 请选择 -' });
    ClrId.forEach((item) =>
      result.set(item, {
        text: echoModel.find((clr) => clr.clsr_id === item)?.clsr_name ?? '',
      }),
    );
    return result;
  });

  

  return (
      <ClassList clrCategoryEnum={clrCategoryEnum}>
        <CreateForm
          teacherEnum={teacherEnum}
          adminEnum={adminEnum}
          jobEnum={jobEnum}
        ></CreateForm>
        <UpdateForm
          teacherEnum={teacherEnum}
          adminEnum={adminEnum}
          jobEnum={jobEnum}
        ></UpdateForm>
        <BeginForm clrCategoryEnum={clrCategoryEnum}></BeginForm>
      </ClassList>
  );
};


export default ClassPage;
